package com.talkyun.openx.ocean;

import com.talkyun.ocean.model.Service;
import com.talkyun.openx.RestfulScanner;
import com.talkyun.openx.ocean.base.HttpInterceptor;
import com.talkyun.openx.server.core.Interceptor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class OceanRestfulScanner extends RestfulScanner {
    private List<Service> list = new ArrayList<Service>();
    private List<HttpInterceptor> httpInterceptorList;

    @Override
    protected void doExport(Object bean, Class<?> api, String mapping) {
        super.doExport(bean, api, mapping);

        Service info = new Service();
        info.setInterfaceName(api.getName());
        info.setServiceMapping(mapping);
        info.setServiceInstance(bean);
        list.add(info);
    }

    List<Service> getAllServiceInfo() {
        return list;
    }

    List<Interceptor> getRestInterceptor() {
        return super.getInterceptor();
    }

    @SuppressWarnings("unchecked")
    public List<HttpInterceptor> getHttpInterceptor() {
        return httpInterceptorList == null ? Collections.EMPTY_LIST : httpInterceptorList;
    }

    public void setHttpInterceptorList(List<HttpInterceptor> httpInterceptorList) {
        this.httpInterceptorList = httpInterceptorList;
    }
}